import React, { useEffect, useMemo } from "react";
// import { useSelector } from "react-redux";
import {  useLocation, useNavigate } from "react-router-dom";
import http from "../../utils/http";
function Ticket() {
  const { state } = useLocation();
//   const citySlice = useSelector((state) => state.citySlice);

  const nav = useNavigate();

  const data = useMemo(() => {
    let n = 0;
    for (let i = 0; i < 1000000; i++) {
      n += i;
    }
    return n;
  }, []);

  useEffect(() => {
    const id = setInterval(() => {
      console.log(111);
    }, 1000);
    http
      .get("/api/trip/train/detail", { params: { id: state.id } })
      .then((res) => {
        console.log(res);
      });
    return () => {
      clearInterval(id);
    };
  }, []);

  return (
    <div>
      {data}
      <button
        onClick={() => {
          nav(`/order_list`, { state: state });
        }}
      >
        去下单
      </button>
      <div
        onClick={() => {
          nav(`/order_list?price=${state.tick.secondTick}`, {
            state: state,
          });
        }}
      >
        {" "}
        二等座：{state.tick.secondTick}
      </div>
      <div
        onClick={() => {
          nav(`/order_list?price=${state.tick.firstTick}`, {
            state: state,
          });
        }}
      >
        {" "}
        一等座：{state.tick.firstTick}
      </div>
      <div
        onClick={() => {
          nav(`/order_list?price=${state.tick.vip}`, {
            state: state,
          });
        }}
      >
        {" "}
        vip：{state.tick.vip}
      </div>
    </div>
  );
}

export default Ticket;
